<div id="formDiv"></div>
<style>
  #productStorageWorkOutForm .layui-form-label {
    width: 120px;
  }

  #productStorageWorkOutForm .layui-input-block {
    margin-left: 150px;
  }

  #productStorageWorkOutForm .layui-form-item .layui-inline {
    margin-right: 0px;
  }
</style>
<script type="text/html" id="formContent">
  <form lay-filter="productStorageWorkOutForm" id="productStorageWorkOutForm" class="layui-form open-form">
    <div class="open-model">
      <div class="open-auto">
        <div class="layui-form-item layui-row">
          <input name="id" type="hidden" />
          <div class="layui-inline layui-col-md3">
            <label class="layui-form-label">出库类型：</label>
            <div class="layui-input-block">
              <select id="outTypeId" name="outTypeId" lay-verify="required" lay-filter="outTypeId" lay-search></select>
              <input name="outTypeName" type="hidden" class="layui-input" disabled id="outTypeName" />
              <input name="outTypeCode" type="hidden" class="layui-input" disabled id="outTypeCode" />
            </div>
          </div>
          <div id="supplierIdDiv" class="layui-inline layui-col-md3">
            <label class="layui-form-label">供应商：</label>
            <div class="layui-input-block">
              <select id="supplierId" name="supplierId" lay-filter="supplierId" lay-search></select>
            </div>
          </div>
          <div id="customerIdDiv" class="layui-inline layui-col-md3">
            <label class="layui-form-label">客户</label>
            <div class="layui-input-block">
              <select id="customerId" name="customerId" lay-filter="customerId"></select>
            </div>
          </div>
          <div class="layui-inline layui-col-md3">
            <label class="layui-form-label">出库任务单：</label>
            <div class="layui-input-block" style="display: flex; align-items: center">
              <!-- <select id="receiptRecordId" name="receiptRecordId" lay-verify="required" lay-filter="receiptRecordId" lay-search></select> -->
              <input name="receiptRecordId" type="hidden" class="layui-input" id="receiptRecordId" />
              <input name="receiptRecordCode" type="text" disabled class="layui-input" id="receiptRecordCode" />
              <button class="layui-btn layui-btn-xs" type="button" id="receiptRecordIdBtn">选择单据</button>
            </div>
          </div>
          <!-- <div class="layui-inline layui-col-md3" >
                        <label class="layui-form-label">出库仓库：</label>
                        <div class="layui-input-block">
                            <input name="receiptWarehouse" type="hidden" class="layui-input" id="receiptWarehouse"
                                   readonly/>
                            <input name="receiptWarehouseName" type="text" class="layui-input" disabled readonly/>
                            <input name="warehouseId" type="hidden" class="layui-input" disabled id="warehouseId"/>
                        </div>
                    </div> -->

          <div class="layui-inline layui-col-md3">
            <label class="layui-form-label">申请备注信息：</label>
            <div class="layui-input-block">
              <input name="remark" type="text" class="layui-input" disabled readonly />
            </div>
          </div>
        </div>
        <div class="layui-form-item layui-row">
          <div class="layui-inline layui-col-md3">
            <label class="layui-form-label">领料申请人：</label>
            <div class="layui-input-block">
              <input name="creatorName" type="text" class="layui-input" disabled readonly />
            </div>
          </div>
          <div class="layui-inline layui-col-md3">
            <label class="layui-form-label">申请时间：</label>
            <div class="layui-input-block">
              <input name="createTime" type="text" class="layui-input" disabled readonly />
            </div>
          </div>
          <div class="layui-inline layui-col-md3">
            <label class="layui-form-label">审核人：</label>
            <div class="layui-input-block">
              <input name="auditPersonName" disabled class="layui-input" />
            </div>
          </div>
          <div class="layui-inline layui-col-md3">
            <label class="layui-form-label">审核时间：</label>
            <div class="layui-input-block">
              <input name="auditTime" disabled class="layui-input" />
            </div>
          </div>
        </div>

        <div class="layui-form-item layui-row">
          <div class="layui-inline layui-col-md3">
            <label class="layui-form-label">申请时间：</label>
            <div class="layui-input-block">
              <input name="createTime" type="text" class="layui-input" disabled readonly />
            </div>
          </div>
          <!--  <div class="layui-inline layui-col-md3">
                            <label class="layui-form-label">供应商分类：</label>
                            <div class="layui-input-block">
                                <div class="layui-input-inline">
                                    <input id="supplierCategoryId" type="hidden" name="supplierCategoryId"/>
                                    <div id="selectSupplierCategory" style="width: 240px"></div>
                                </div>
                            </div>
                        </div>
-->
        </div>

        <div class="title" style="margin-bottom: 15px">出库明细</div>

        <div class="layui-form-item tableContent">
          <!-- {{# if(['add','edit','outbound'].includes(d.eventName)){ }} -->
          <button class="layui-btn" type="button" id="ConfigureBtn">配置物料信息</button>
          <!-- {{# } }} -->
          <table class="layui-table" id="productStorageWorkOutFormTable" lay-filter="productStorageWorkOutFormTable"></table>
        </div>
      </div>
      <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">关闭</button>
        <!-- {{# if(!['acceptance','details'].includes(d.eventName)){ }} -->
        <button class="layui-btn" lay-filter="inquiryOrderInformationSubmit" type="button" lay-submit>提交</button>
        <!-- {{# } }} -->
      </div>
    </div>
  </form>
</script>

<script type="text/html" id="productStorageWorkOutFormTableBar">
  <!-- {{# if(d.eventName=='acceptance'&&d.statusDesc=='待受理'){ }} -->
  <button class="layui-btn layui-btn-xs" lay-event="accept" type="button">受理/评审</button>
  <!-- {{# } }} -->
  <!-- {{# if(d.eventName=='acceptance'&&d.statusDesc!='待受理'){ }} -->
  <button class="layui-btn layui-btn-xs" lay-event="acceptDetail" type="button">查看详情</button>
  <!-- {{# } }} -->
  <!-- {{# if(['edit',undefined].includes(d.eventName)){ }} -->
  <button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" type="button">删除</button>
  <!-- {{# } }} -->
</script>
<script>
  layui.use(["layer", "form", "table", "admin", "laydate", "upload", "laytpl"], async function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var config = layui.config;
    var admin = layui.admin;
    var upload = layui.upload;
    let laydate = layui.laydate;
    let laytpl = layui.laytpl;
    const nowData = { ...parentData };
    let data = nowData?.data;
    // const loadingIndex = layer.load();
    laytpl(formContent.innerHTML).render({ ...nowData }, function (html) {
      $("#formDiv").after(html);
    });
    // add新增 edit修改 detail详情 offer报价 quotationRecord报价记录 acceptance受理/评审
    // $("#contractIdFormDiv").hide();

    $("#customerIdDiv").hide();
    $("#supplierIdDiv").hide();
    form.on('select(outTypeId)', function () {
      debugger;
      if ($("#outTypeId").val() == 3) {//生产订单出库
        $("#supplierIdDiv").show();
        $("#customerIdDiv").hide();
      } else if ($("#outTypeId").val() == 4) {//成品销售出库
        $("#customerIdDiv").show();
        $("#supplierIdDiv").hide();
      } else {
        $("#customerIdDiv").hide();
        $("#supplierIdDiv").hide();
      }
    });

      await admin.initDataSelectPro(
      "enterprise/sell/admin/customersInfo/list",
      { limit: 99999 },
      "customerId",
      "客户名称",
      async (d, obj) => {
        form.val("finishedOrderForm", {
          agentCategoryName: obj?.agentCategoryName
        });
        /*  await admin.initDataSelectPro('enterprise/sell/admin/contactInfo/list', {selCustomerId: d.value}, 'contactId', '客户联系人', (d, obj) => {
                form.val('finishedOrderForm', {
                    telephone: '',
                    department: '',
                })
                form.val('finishedOrderForm', {
                    telephone: obj.telephone,
                    department: obj.department,
                })
            })*/
      },
      "customerName"
    );

    // admin.initDataSelectTree(
    //   true,
    //   "enterprise/purchase/admin/supplierCategory/getTreeData",
    //   null,
    //   "selectSupplierCategory",
    //   data ? data.supplierCategoryId : null,
    //   "供应商分类",
    //   "supplierCategoryId",
    //   function (data) {
    //     //供应商分类ID
    //     let supplierCategoryId = data.change[0].value;
    //     //清空供应商分类ID
    //     $("#supplierId").empty();
    //     //清空采购订单列表
    //     /*    $('#purchaseOrderId').empty();*/
    //     //供应商列表
        admin.initDataSelect(
          "enterprise/purchase/admin/supplierInfoPass/list",
          // { limit: 99999, supplierCategoryId: supplierCategoryId },
                { limit: 99999},
                "supplierId",
          null,
          "供应商",
          "corporateName",
          null
        );
    //   }
    // );

    await admin.initDataSelectPro(
      "enterprisecab/warehouse/admin/warehouseInventoryType/list",
      { inventoryType: "out", limit: 9999, status: "enable" },
      "outTypeId",
      "出库类型",
      async (d, obj) => {
        form.val("productStorageWorkOutForm", {
          receiptWarehouseName: "",
          remark: "",
          creatorName: "",
          createTime: "",
          auditPersonName: "",
          auditTime: "",
          receiptRecordId: "",
          outTypeCode: "",
          outTypeName: "",
          outTypeId: ""
        });

        $("#outTypeCode").val(obj.code);
        $("#outTypeName").val(obj.name);
        $("#outTypeId").val(obj.id);

        table.reload("productStorageWorkOutFormTable", {
          data: []
        });
        $("#receiptRecordId").empty();
        form.render("select");
        await admin.initDataSelectPro(
          "enterprise/receiptRecord/admin/receiptRecord/list",
          {
            status: 2,
            limit: 9999,
            inventoryTypeCode: obj.code,
            flagStatus: 1
          },
          "receiptRecordId",
          "出库任务单/领料申请",
          (d, obj) => {
            form.val("productStorageWorkOutForm", {
              receiptWarehouseName: "",
              remark: "",
              creatorName: "",
              createTime: "",
              auditPersonName: "",
              auditTime: ""
            });
            table.reload("productStorageWorkOutFormTable", {
              data: []
            });
            form.val("productStorageWorkOutForm", {
              receiptWarehouseName: obj.receiptWarehouseName,
              receiptWarehouse: obj.receiptWarehouse,
              warehouseId: obj.receiptWarehouse,
              remark: obj.remark,
              creatorName: obj.creatorName,
              createTime: obj.createTime,
              auditPersonName: obj.auditPersonName,
              auditTime: obj.auditTime
            });
          },
          "code"
        );
      }
    );

    // form.on('select(customerId)',function (data){
    table.render({
      elem: "#productStorageWorkOutFormTable",
      page: false,
      limit: 999999,
      data: [],
      cols: [
        [
          { type: "numbers", width: 50, title: "序号" },
          { field: "productDetailId", title: "物料ID", hide: true },
          { field: "skuCode", title: "物料编码", align: "center" },
          {
            field: "skuName",
            title: "出库物料名称",
            align: "center"
          },
          { field: "skuSpec", title: "规格码", align: "center" },
          {
            field: "warehouseShelfSpaceId",
            title: "出库库位",
            align: "center",
            width: 150,
            templet: (d) => {
              if (d.warehouseShelfSpaceIdList && d.warehouseShelfSpaceIdList.length > 0) {
                let options = d.warehouseShelfSpaceIdList;
                return admin.setTableSelect("warehouseShelfSpaceId", options, false, "warehouseShelfSpaceId")(d);
              } else {
                return "无库存";
              }
            }
          },
          {
            field: "palletBoxId",
            title: "载具编号",
            align: "center",
            width: 150,
            templet: (d) => {
              if (d.palletBoxIdList && d.palletBoxIdList.length > 0 && d.warehouseShelfSpaceId) {
                let options = d.palletBoxIdList;
                return admin.setTableSelect("palletBoxId", options, false, "palletBoxId")(d);
              } else {
                return "无料箱";
              }
            }
          },
          { field: "receiptNum", title: "本单申请出库量", align: "center" },
          { field: "leaveQuantity", title: "本单剩余出库量", align: "center" },
          { field: "warehouseName", title: "仓库名称", align: "center" },
          {
            field: "warehouseId",
            title: "仓库Id",
            align: "center",
            hide: true
          },
          { field: "inventoryQuantity", title: "可用库存", align: "center" },
          { field: "mainUnitName", title: "主单位", align: "center" },
          {
            field: "outNum",
            title: "主单位出库数量",
            align: "center",
            templet: admin.setTableInput("outNum", false, "outNum")
          },
          // {
          //   field: "subUnitName",
          //   title: "辅单位",
          //   align: "center",
          // },
          // {
          //   field: "subOutNum",
          //   title: "辅单位出库数量",
          //   align: "center",
          // },
          // , {field: 'remark', title: '备注', align: 'center', width: 160, edit: 'text'}
          {
            align: "center",
            toolbar: "#productStorageWorkOutFormTableBar",
            title: "操作",
            width: 100
          }
        ]
      ],
      done: function (res, curr, count) {
        $(".layui-table-body, .layui-table-box, .layui-table-cell").css("overflow", "visible"); //显示高于表格
        admin.tableSelectChange("productStorageWorkOutFormTable", "warehouseShelfSpaceId", async (index, value, tableData, field) => {
          if (!value) {
            tableData[index].palletBoxIdList = [];
            tableData[index].palletBoxId = "";
            tableData[index].inventoryQuantity = 0;
            tableData[index].warehouseName = "";
            tableData[index].warehouseId = "";
            table.reload("productStorageWorkOutFormTable");
            return;
          }
          const res = await admin.reqPro("enterprise/palletBoxSkuIterm/admin/palletBoxSkuIterm/getPalletBoxList", { shelfSpaceId: value, skuCode: tableData[index].skuCode });
          console.log(tableData[index].warehouseShelfSpaceIdList);
          let obj = tableData[index].warehouseShelfSpaceIdList.find((v) => v.value == value);
          tableData[index].palletBoxId = "";
          tableData[index].warehouseName = obj.warehouseName;
          tableData[index].warehouseId = obj.warehouseId;
          tableData[index].inventoryQuantity = obj.num;
          tableData[index].palletBoxIdList = res.data
            .filter((v) => v.palletBoxCode != "")
            .map((v) => {
              return {
                value: v.palletBoxId,
                label: v.palletBoxCode ? v.palletBoxCode : "无料箱",
                num: v.num
              };
            });
          // tableData[index].allList.filter(v => v.value == value).map(v => {
          //     return {
          //         value: v.palletBoxId,
          //         label: v.palletBoxCode
          //     }
          // })
          console.log("tableData", tableData);
          table.reload("productStorageWorkOutFormTable");
        });
        admin.tableSelectChange("productStorageWorkOutFormTable", "palletBoxId", (index, value, tableData, field) => {
          console.log(tableData[index]);
          console.log(tableData[index].palletBoxIdList.find((v) => v.value == value));
          let obj = tableData[index].palletBoxIdList.find((v) => v.value == value);
          if (obj) {
            tableData[index].inventoryQuantity = obj.num;
          } else {
            tableData[index].inventoryQuantity = 0;
          }
          table.reload("productStorageWorkOutFormTable");
        });
        admin.tableInputChangeByClass("productStorageWorkOutFormTable", "outNum", (index, value, tableData, field, tableId) => {
          let mainUnitRate = tableData[index].mainUnitRate;
          let subUnitRate = tableData[index].subUnitRate;
          if (mainUnitRate && subUnitRate && value) {
            let subtotal = value * mainUnitRate;
            tableData[index].subOutNum = subtotal;
            admin.setTableColHtml(tableId, index, "subOutNum", subtotal);
          } else {
            tableData[index].subOutNum = "";
            admin.setTableColHtml(tableId, index, "subOutNum", "");
          }
        });
      }
    });

    // table.on("tool(productStorageWorkOutFormTable)", function (obj) {
    //   console.log(obj);
    //   if (obj.event === "delete") {
    //     const index = $(obj.tr[0]).data("index");
    //     let list = table.cache["productStorageWorkOutFormTable"].filter((v) => {
    //       return v["LAY_TABLE_INDEX"] != index;
    //     });
    //     console.log(123,);

    //     table.reload("productStorageWorkOutFormTable", {
    //       data: list
    //     });
    //   }
    // });

    if (data && data.id) {
    } else {
    }
    if (nowData.eventName === "outbound") {
      let obj = nowData.data;
      obj.receiptRecordId = obj.id;
      obj.receiptRecordCode = obj.code;
      obj.outTypeId = obj.inventoryTypeId;
      $("#outTypeId").attr("disabled", true);
      $("#receiptRecordIdBtn").hide();
      delete obj.id;
      form.val("productStorageWorkOutForm", {
        ...obj
      });
      admin.req("enterprise/receiptRecord/admin/receiptRecord/get", { id: obj.receiptRecordId }, async (res) => {
        if (res.code === 200) {
          let newData = res.data.receiptRecordDetailList;
          for (let v of newData) {
            v.inventoryQuantity = 0;
            let res = await admin.reqPro("enterprise/warehouseSkuIterm/admin/warehouseSkuIterm/getSkuShelfSpaceCode", {
              skuCode: v.skuCode
            });

            if (res.code === 200) {
              if (res.data.length > 0) {
                let obj = res.data[0];
                v.palletBoxId = "";
                v.warehouseName = obj.warehouseName;
                v.warehouseId = obj.warehouseId;
                v.inventoryQuantity = obj.num;
                v.palletBoxIdList = res.data;
              }
              let list = res.data;
              let warehouseShelfSpaceIdList = list.map((v) => {
                return v;
              });

              // .filter(v => {
              //   if(v.receiptWarehouse!==0){
              //     return true
              //   }
              // })

              //  .filter((v, index) => {
              //         if (index === list.findIndex(item => item.warehouseShelfSpaceId === v.warehouseShelfSpaceId)) {
              //             return true
              //         }
              //     })
              // v.allList = list.map(item => ({
              //     value: item.warehouseShelfSpaceId,
              //     label: item.warehouseShelfSpaceCode,
              //     palletBoxCode: item.palletBoxCode,
              //     palletBoxId: item.palletBoxId
              // }));
              console.log(obj);
              
              v.warehouseShelfSpaceIdList = warehouseShelfSpaceIdList
                .map((item, i) => {
                  item.value = item.shelfSpaceId;
                  item.label = item.shelfSpaceCode;
                  return item;
                })
                .filter((v) => {
                  if (obj.receiptWarehouse - 0 > 0) {
                    return v.warehouseId == obj.receiptWarehouse;
                  } else {
                    return true;
                  }
                });

              v.receiptRecordDetailId = v.id;
              // v.warehouseShelfSpaceIdList=[]
            }
          }
          const oldData = table.cache["productStorageWorkOutFormTable"];

          let list = [...oldData, ...newData];
          console.log(11111, list);
          list = await Promise.all(
            list.map(async (v) => {
              if (v.warehouseShelfSpaceIdList && v.warehouseShelfSpaceIdList.length > 0) {
                v.warehouseShelfSpaceId = v.warehouseShelfSpaceIdList[0].value;
                const res = await admin.reqPro("enterprise/palletBoxSkuIterm/admin/palletBoxSkuIterm/getPalletBoxList", {
                  shelfSpaceId: v.warehouseShelfSpaceId,
                  skuCode: v.skuCode
                });
                console.log(res);
                v.palletBoxIdList = res.data
                  .filter((v) => v.palletBoxCode != "")
                  .map((v) => {
                    return {
                      value: v.palletBoxId,
                      label: v.palletBoxCode ? v.palletBoxCode : "无料箱",
                      num: v.num
                    };
                  });
                if (v.palletBoxIdList.length > 0) {
                  v.palletBoxId = v.palletBoxIdList[0].value;
                }
              }
              v.outNum = v.leaveQuantity;
              return v;
            })
          );

          console.log("list", list);
          table.reload("productStorageWorkOutFormTable", {
            data: list // 设置新的数据
          });
        }
      });
    }

    form.on("submit(inquiryOrderInformationSubmit)", function (d) {
      let flag = false;
      let tableList = table.cache["productStorageWorkOutFormTable"];
      if (tableList.length === 0) {
        layer.msg("请添加出库信息", { icon: 2 });
        return false;
      }
      tableList.forEach((detail) => {
        if (!detail.outNum) {
          layer.msg(`物料【${detail.skuName}】出库数量不能为空`, { icon: 2 });
          flag = true;
          return false;
        }
        if (!detail.warehouseShelfSpaceId) {
          layer.msg(`物料【${detail.skuName}】出库库位不能为空`, { icon: 2 });
          flag = true;
          return false;
        }
        if (detail.palletBoxIdList && detail.palletBoxIdList.length > 0 && !detail.palletBoxId) {
          layer.msg(`物料【${detail.skuName}】载具编号不能为空`, { icon: 2 });
          flag = true;
          return false;
        }
      });
      // 控制不能提交为空的数据
      if (flag) {
        return false;
      }
      let formData = { ...d.field };
      formData.productStorageWorkOutDetailList = table.cache["productStorageWorkOutFormTable"].map((v) => {
        //   v.warehouseId = formData.warehouseId;
        //   v.receiptWarehouse = formData.receiptWarehouse;
        //   v.receiptWarehouseName = formData.receiptWarehouseName;
        return v;
      });
      console.log(formData);

      admin.req(
        "enterprise/storage/admin/productStorageWorkOut/add",
        JSON.stringify(formData),
        function (res) {
          layer.closeAll("loading");
          if (res.code == 200) {
            // 提交成功清空缓存数据
            layer.msg(res.msg, { icon: 1 });
            layer.closeAll();
            table.reload("#productStorageWorkOutTable");
          } else {
            layer.msg(res.msg, { icon: 2 });
          }
        },
        "POST",
        true,
        "application/json; charset=utf-8"
      );
      return false;
    });
    table.on("tool(productStorageWorkOutFormTable)", function (obj) {
      var d = obj.data; // 获取当前行的数据
      var layEvent = obj.event; // 获取事件名（edit 或 del）
      if (obj.tr) {
        obj.tr.on("click", function (e) {
          e.preventDefault(); // 防止默认行为
        });
      }
      if (layEvent == "del") {
        const index = $(obj.tr[0]).data("index");
        let list = table.cache["productStorageWorkOutFormTable"].filter((v) => {
          return v["LAY_TABLE_INDEX"] != index;
        });
        table.reload("productStorageWorkOutFormTable", {
          data: list
        });
      }
    });
    $("#receiptRecordIdBtn").click(function () {
      if (!$("#outTypeId").val()) {
        layer.msg("请先选择出库类型");
        return;
      }
      admin.formOpen({
        area: ["90%", "90%"],
        offset: "50px",
        title: "选择出库任务单",
        path: "components/storage/receiptApply1.html",
        success: function () {
          parentData.eventName = "radio";
          parentData.where = {
            inventoryTypeId: $("#outTypeId").val(),
            status: '2'
          };

          // parentData.dataList = res.data.receiptRecordDetailList;
        },
        end: function () {
          table.reload("productStorageWorkOutFormTable", {
            data: [] // 设置新的数据
          });
          console.log(childData);
          if (childData.list && childData.list.length > 0) {
            let list = childData.list;
            let obj = list[0];
            obj.receiptRecordId = obj.id;
            obj.receiptRecordCode = obj.code;
            delete obj.id;
            form.val("productStorageWorkOutForm", {
              ...obj
            });
            console.log(123, list);
            admin.req("enterprise/receiptRecord/admin/receiptRecord/get", { id: obj.receiptRecordId }, async (res) => {
              if (res.code === 200) {
                let newData = res.data.receiptRecordDetailList;
                for (let v of newData) {
                  v.inventoryQuantity = 0;
                  let res = await admin.reqPro("enterprise/warehouseSkuIterm/admin/warehouseSkuIterm/getSkuShelfSpaceCode", {
                    skuCode: v.skuCode
                  });

                  if (res.code === 200) {
                    if (res.data.length > 0) {
                      let obj = res.data[0];
                      v.palletBoxId = "";
                      v.warehouseName = obj.warehouseName;
                      v.warehouseId = obj.warehouseId;
                      v.inventoryQuantity = obj.num;
                      v.palletBoxIdList = res.data;
                    }
                    let list = res.data;
                    let warehouseShelfSpaceIdList = list.map((v) => {
                      return v;
                    });

                    //  .filter((v, index) => {
                    //         if (index === list.findIndex(item => item.warehouseShelfSpaceId === v.warehouseShelfSpaceId)) {
                    //             return true
                    //         }
                    //     })
                    // v.allList = list.map(item => ({
                    //     value: item.warehouseShelfSpaceId,
                    //     label: item.warehouseShelfSpaceCode,
                    //     palletBoxCode: item.palletBoxCode,
                    //     palletBoxId: item.palletBoxId
                    // }));
                    v.warehouseShelfSpaceIdList = warehouseShelfSpaceIdList
                      .map((item) => {
                        item.value = item.shelfSpaceId;
                        item.label = item.shelfSpaceCode;
                        return item;
                      })
                      .filter((v) => {
                        if (obj.receiptWarehouse - 0 > 0) {
                          return v.warehouseId == obj.receiptWarehouse;
                        } else {
                          return true;
                        }
                      });
                    v.receiptRecordDetailId = v.id;
                    // v.warehouseShelfSpaceIdList=[]
                  }
                }
                const oldData = table.cache["productStorageWorkOutFormTable"];
                let list = [...oldData, ...newData];
                // 去重
                list = list.filter((v, index, self) => {
                  return self.findIndex((t) => t.skuCode === v.skuCode) === index;
                });
                list = await Promise.all(
                  list.map(async (v) => {
                    if (v.warehouseShelfSpaceIdList && v.warehouseShelfSpaceIdList.length > 0) {
                      v.warehouseShelfSpaceId = v.warehouseShelfSpaceIdList[0].value;
                      const res = await admin.reqPro("enterprise/palletBoxSkuIterm/admin/palletBoxSkuIterm/getPalletBoxList", {
                        shelfSpaceId: v.warehouseShelfSpaceId,
                        skuCode: v.skuCode
                      });
                      console.log(res);
                      v.palletBoxIdList = res.data
                        .filter((v) => v.palletBoxCode != "")
                        .map((v) => {
                          return {
                            value: v.palletBoxId,
                            label: v.palletBoxCode ? v.palletBoxCode : "无料箱",
                            num: v.num
                          };
                        });
                      if (v.palletBoxIdList.length > 0) {
                        v.palletBoxId = v.palletBoxIdList[0].value;
                      }
                    }
                    v.outNum = v.leaveQuantity;
                    return v;
                  })
                );

                table.reload("productStorageWorkOutFormTable", {
                  data: list // 设置新的数据
                });
              }
            });
          }
        }
      });
    });

    //判断QTC出库是否选择了仓库
    $("#ConfigureBtn").click(function () {
      const id = $("#receiptRecordId").val();
      if (id) {
        admin.req("enterprise/receiptRecord/admin/receiptRecord/get", { id }, (res) => {
          if (res.code === 200) {
            admin.formOpen({
              area: ["90%", "80%"],
              offset: "50px",
              title: "配置订单物料信息",
              path: "components/storage/productStorageWorkOutFormTable.html",
              success: function () {
                parentData.dataList = res.data.receiptRecordDetailList;
                parentData.cacheList = [...table.cache["productStorageWorkOutFormTable"]];
              },
              end: async function () {
                if (childData.list) {
                  let newData = childData.list || [];
                  for (let v of newData) {
                    v.inventoryQuantity = 0;
                    let res = await admin.reqPro("enterprise/warehouseSkuIterm/admin/warehouseSkuIterm/getSkuShelfSpaceCode", {
                      skuCode: v.skuCode
                    });

                    if (res.code === 200) {
                      if (res.data.length > 0) {
                        let obj = res.data[0];
                        v.palletBoxId = "";
                        v.warehouseName = obj.warehouseName;
                        v.warehouseId = obj.warehouseId;
                        v.inventoryQuantity = obj.num;
                        v.palletBoxIdList = res.data;
                      }
                      let list = res.data;
                      let warehouseShelfSpaceIdList = list.map((v) => {
                        return v;
                      });

                      //  .filter((v, index) => {
                      //         if (index === list.findIndex(item => item.warehouseShelfSpaceId === v.warehouseShelfSpaceId)) {
                      //             return true
                      //         }
                      //     })
                      // v.allList = list.map(item => ({
                      //     value: item.warehouseShelfSpaceId,
                      //     label: item.warehouseShelfSpaceCode,
                      //     palletBoxCode: item.palletBoxCode,
                      //     palletBoxId: item.palletBoxId
                      // }));
                      v.warehouseShelfSpaceIdList = warehouseShelfSpaceIdList.map((item) => {
                        item.value = item.shelfSpaceId;
                        item.label = item.shelfSpaceCode;
                        return item;
                      });

                      v.receiptRecordDetailId = v.id;
                      // v.warehouseShelfSpaceIdList=[]
                    }
                  }
                  const oldData = table.cache["productStorageWorkOutFormTable"];

                  let list = [...oldData, ...newData];
                  // list去重
                  list = list.filter((v, index, self) => {
                    return self.findIndex((t) => t.skuCode === v.skuCode) === index;
                  });
                  list = await Promise.all(
                    list.map(async (v) => {
                      if (v.warehouseShelfSpaceIdList && v.warehouseShelfSpaceIdList.length > 0) {
                        v.warehouseShelfSpaceId = v.warehouseShelfSpaceIdList[0].value;
                        const res = await admin.reqPro("enterprise/palletBoxSkuIterm/admin/palletBoxSkuIterm/getPalletBoxList", {
                          shelfSpaceId: v.warehouseShelfSpaceId,
                          skuCode: v.skuCode
                        });
                        console.log(res);
                        v.palletBoxIdList = res.data
                          .filter((v) => v.palletBoxCode != "")
                          .map((v) => {
                            return {
                              value: v.palletBoxId,
                              label: v.palletBoxCode ? v.palletBoxCode : "无料箱",
                              num: v.num
                            };
                          });
                        if (v.palletBoxIdList.length > 0) {
                          v.palletBoxId = v.palletBoxIdList[0].value;
                        }
                      }
                      v.outNum = v.leaveQuantity;
                      return v;
                    })
                  );

                  console.log("list", list);
                  table.reload("productStorageWorkOutFormTable", {
                    data: list // 设置新的数据
                  });
                }
              }
            });
          }
        });
      } else {
        layer.msg("请选择出库任务单/领料申请");
      }
    });
  });
</script>
